class Life extends React.Component{
	state={opacity:1};
  death=()=>{
  // 卸载组件
		ReactDOM.unmountComponentAtNode(document.getElementById('test'))
	}
	// 组件挂载完毕之后调用
	componentDidMount(){
  	this.timer=setInterval(()=>{
  		let {opacity}=this.state;
  		opacity-=0.1;
  		if (opacity<=0) opacity=1;
  		this.setState({opacity});
		},200)
		console.log("挂载完成了")
	}
	// 组件将要卸载
	componentWillUnmount(){
		console.log("组件将要卸载")
		clearInterval(this.timer);
	}
	render(){
		return(
			<div>
				<h2 style={{opacity:this.state.opacity}}>React学不会怎么办</h2>
				<button onClick={this.death}>不活了</button>
			</div>
		)
	}
}
ReactDOM.render(<Life/>,document.getElementById('test'));
